const { app, BrowserWindow,Tray } = require('electron')
const path = require('path')

function createWindow () {
  
  const win = new BrowserWindow({
    width: 1366,
    height: 800,
    //fullscreen: true, // 添加此行以使窗口默认全屏
    frame: true, // 将此行更改为true以启用框架
    icon: path.join(__dirname, 'logo.jpg'), // 添加此行以设置图标
    maximizable:true,
    minimizable: true, // 添加此行以启用最小化
    closable: true, // 将此行更改为false以禁用关闭
    // show: false // 添加此行以最初隐藏窗口
  })

  win.loadURL('https://gofly.v1kf.com/main')
  //隐藏顶部菜单
  win.setMenu(null);

  //托盘图标
  let tray = new Tray(path.join(__dirname, 'logo.jpg'))
  //点击托盘图标显示窗口
  tray.on('click', () => {
    win.show()
  })
  //设置托盘提示
  tray.setToolTip('客服系统')
  const { Menu } = require('electron')
  //设置托盘菜单
  const contextMenu = Menu.buildFromTemplate([
    { label: '退出', click: () => { app.exit() } }
  ])
  tray.setContextMenu(contextMenu)
  
  //窗口关闭事件
  win.on('close', (event) => {
    event.preventDefault()
    win.hide()
    //显示托盘提示
    tray.displayBalloon({
      title:"客服系统",
      content:"已隐藏在托盘处",
    })
  })
      
}

app.whenReady().then(() => {
  createWindow()

  app.on('activate', () => {
    if (BrowserWindow.getAllWindows().length === 0) {
      createWindow()
    }
  })
})

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit()
  }
})
